clear all
cd "C:\Users\ot3\Documents\TeacherDeseg\Census"

set more off

clear
quietly infix                 ///
  int     year       1-4      ///
  byte    datanum    5-6      ///
  double  serial     7-14     ///
  double  hhwt       15-24    ///
  byte    region     25-26    ///
  byte    statefip   27-28    ///
  byte    urban      29-29    ///
  byte    gq         30-30    ///
  int     pernum     31-34    ///
  double  perwt      35-44    ///
  byte    sex        45-45    ///
  int     age        46-48    ///
  int     birthyr    49-52    ///
  byte    race       53-53    ///
  int     raced      54-56    ///
  byte    hispan     57-57    ///
  int     hispand    58-60    ///
  int     bpl        61-63    ///
  long    bpld       64-68    ///
  byte    educ       69-70    ///
  int     educd      71-73    ///
  byte    empstat    74-74    ///
  byte    empstatd   75-76    ///
  byte    labforce   77-77    ///
  int     occ1950    78-80    ///
  int     ind1950    81-83    ///
  long    inctot     84-90    ///
  long    ftotinc    91-97    ///
  long    incwage    98-103   ///
  int     poverty    104-106  ///
  byte    migrate5   107-107  ///
  byte    migrate5d  108-109  ///
  int     migplac5   110-112  ///
  byte    work5yr    113-113  ///
  int     occ5yr95   114-116  ///
  int     ind5yr     117-119  ///
  using `"usa_00061.dat"'

replace hhwt      = hhwt      / 100
replace perwt     = perwt     / 100

format serial    %8.0f
format hhwt      %10.2f
format perwt     %10.2f


*Note: Data already restricted to non-Hispanic, black or white, at least 1 year college, 

*Race, sex, education
recode race (1=0)(2=1)(else=.), gen(black)
recode sex (1=1)(2=0), gen(male)
recode educ (7 8 9=1)(10=2) (11=3)  


*Define regions
g bornsouth=inlist(bpl, 1, 5, 12, 13, 22, 28, 37, 45, 47, 48, 51)
replace bornsouth=. if bpl==.

g livesouth=inlist(statefip, 1, 5, 12, 13, 22, 28, 37, 45, 47, 48, 51)  
replace livesouth=. if statefip==.

*Employment outcomes
drop if occ1950==997 | occ1950==999

recode empstat (1=0)(2 3=1), gen(outlforce)

recode occ1950 (93=1)(else=0), gen(teacher)
replace teacher=0 if outlforce==1 //respondents report an occupation if they have wroked in past 10 years, even if not working now

recode occ1950 (0/92 94/99=1)(else=0), gen(professional)  
replace professional=0 if outlforce==1

g teachersouth=teacher==1 & livesouth==1 & outlforce==0
g profsouth=professional==1 & livesouth==1 & outlforce==0
g othersouth=teacher==0 & professional==0 & livesouth==1 & outlforce==0
g teachernorth=teacher==1 & livesouth==0 & outlforce==0
g nonteachernorth=teacher==0 & livesouth==0 & outlforce==0

*earnings
cpigen
replace incwage=incwage/cpiu
replace incwage=25000/.1717446 if year==1970 & incwage>25000/.1717446
g learn=ln(incwage)

*Means quoted in introduction
tab occ1950 if black==1 & livesouth==1 & year==1960 & outlforce==0 [aweight=perwt]


save MainWorking, replace














***Table 4: Main Census Estimates***
use MainWorking, clear

*Age and region of birth restrictions
keep if (year==1960 & age>=25 & age<=55) | (year==1970 & age>=35 & age<=65)
keep if bornsouth==1 

g y1970=year==1970
g treat=y1970*black
g agein1964=1964-birthyr

*Baseline means
sum teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce if year==1960 & black==1 
sum teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce if male==0 & year==1960 & black==1 
sum teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce if male==1 & year==1960 & black==1 

*Regressions
local outcomes="teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce"
foreach x of varlist `outcomes'  {
qui reg `x'  black y1970 treat i.bpl i.birthyr i.educ male , robust
est sto `x'
qui reg `x'  black y1970 treat i.bpl i.birthyr i.educ if male==0 , robust
est sto `x'female
qui reg `x'  black y1970 treat i.bpl i.birthyr i.educ if male==1  , robust
est sto `x'male
qui reg `x'  black y1970 treat i.bpl  i.educ male if agein1964<=40 , robust
est sto `x'young
qui reg `x'  black y1970 treat i.bpl i.birthyr i.educ male if agein1964>40 , robust
est sto `x'old
}

outreg2 [*] using T1, keep(treat)  dec(3)  nocons nor2  replace 



*Placebo for 1950 to 1960 (Panel B)
use GroupedWorking, clear

*Age and region of birth restrictions
keep if (year==1950 & age>=25 & age<=55) | (year==1960 & age>=35 & age<=65) 
keep if bornsouth==1


*generate new vars
g y1960=year==1960
g treat=y1960*black

*Regressions
local outcomes="teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce"
foreach x of varlist `outcomes'  {
qui reg `x'  black y1960 treat i.bpl i.birthyr i.educ male, robust
est sto `x'
}
outreg2 [*] using T1, keep(treat)  dec(3)  nocons nor2  replace 



*Cross-model significance tests
*Gender
local outcomes="teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce"
foreach x of varlist `outcomes'  {
qui reg `x'  black y1970 treat i.bpl i.birthyr i.educ if male==0 
est sto `x'female
qui reg `x'  black y1970 treat i.bpl i.birthyr i.educ if male==1  
est sto `x'male

qui suest `x'female `x'male, vce(robust)
test [`x'female_mean]treat - [`x'male_mean]treat = 0  
}


*Age
local outcomes="teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce"
foreach x of varlist `outcomes'  {
qui reg `x'  black y1970 treat i.bpl  i.educ male if agein1964<=40 
est sto `x'young
qui reg `x'  black y1970 treat i.bpl  i.educ male if agein1964>40 
est sto `x'old

qui suest `x'young `x'old, vce(robust)
test [`x'young_mean]treat - [`x'old_mean]treat = 0   
}







***Table 6: Earnings Effects***
use GroupedWorking, clear


*Age and region of birth restrictions
keep if (year==1960 & age>=25 & age<=55) | (year==1970 & age>=35 & age<=65)
keep if bornsouth==1 

g y1970=year==1970
g treat=y1970*black
g bXteachersouth=black*teachersouth


*Regressions
qui reg learn  black y1970 treat  i.bpl i.birthyr i.educ male  , robust
est sto base
qui reg learn  black y1970 treat teachersouth bXteachersouth i.bpl i.birthyr i.educ male  , robust
est sto full


qui reg learn teachersouth    i.bpl i.birthyr i.educ male  if year==1960 & black==1, robust
est sto b1960
qui reg learn teachersouth    i.bpl i.birthyr i.educ male  if year==1970 & black==1, robust
est sto b1970

outreg2 [*] using T1, keep(black y1970 treat teachersouth bXteachersouth)  dec(3)  nocons nor2  replace 


*Additional results quoted in text
reg learn   y1970   i.bpl i.birthyr i.educ male  if black==1 & teachersouth==1, robust
reg learn   y1970   i.bpl i.birthyr i.educ male  if black==0 & teachersouth==1, robust
reg learn   y1970   i.bpl i.birthyr i.educ male  if black==1 & teachersouth==0, robust
reg learn   y1970   i.bpl i.birthyr i.educ male  if black==0 & teachersouth==0, robust


*Gelbach (for sign tests)
tab bpl, gen(BP)
tab birthyr, gen(C)
tab educ, gen(E)
g teachersouth1970=teachersouth*y1970
b1x2 learn , x1all(black y1970 treat male BP* C* E*) x1only(treat) x2all(teachersouth bXteachersouth ) robust








***Table A2***
*Panel A:No Controls
use GroupedWorking, clear

*Age and region of birth restrictions
keep if (year==1960 & age>=25 & age<=55) | (year==1970 & age>=35 & age<=65)
keep if bornsouth==1 

g y1970=year==1970
g treat=y1970*black
g agein1964=1964-birthyr


*Regressions
local outcomes="teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce"
foreach x of varlist `outcomes'  {
qui reg `x'  black y1970 treat , robust
est sto `x'
}

outreg2 [*] using T1, keep(treat)  dec(3)  nocons nor2  replace 


*Panel B: 1970 to 1980 
use GroupedWorking, clear

*Age and region of birth restrictions
keep if (year==1970 & age>=25 & age<=55) | (year==1980 & age>=35 & age<=65) 
keep if bornsouth==1

*generate new vars
g y1980=year==1980
g treat=y1980*black

*Regressions
local outcomes="teachersouth profsouth othersouth teachernorth   nonteachernorth  outlforce"
foreach x of varlist `outcomes'  {
qui reg `x'  black y1980 treat i.bpl i.birthyr i.educ male , robust
est sto `x'
}
outreg2 [*] using T1, keep(treat)  dec(3)  nocons nor2  replace 











